/*
 * (c) 2016 <tang-haifeng@foxmail.com> <pengren.mcu@qq.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 *
 */

#ifndef __LS1B_CORE_CONFIG_H
#define __LS1B_CORE_CONFIG_H

#include <linux/sizes.h>

#define LS1X_SPI_SFC_PARAM	0x17	/* 设置SPI flash控制器的模式，加快启动
									div 2, double I/O + burst_en + memory_en 模式
									部分SPI flash可能不支持 导致启动不了 根据使用的spi flash型号修改 */

#define OSC_CLK		25000000 /* Hz */
#if 0
#define PLL_FREQ	0x1a
#define CPU_DIV		0x2
#define DDR_DIV		0x3
#else
#define PLL_FREQ	0x2a
#define CPU_DIV		0x3
#define DDR_DIV		0x5
#endif
#define PLL_DIV		(0x92082a00 | (CPU_DIV<<20) | (DDR_DIV<<14)) /* ((1<<31)|(4<<26)|(1<<25)|(1<<19)|0x2a00) */
#define PLL_CLK		((12+(PLL_FREQ&0x3f))*OSC_CLK/2 + ((PLL_FREQ>>8)&0x3ff)*OSC_CLK/2/1024)

#define LS1X_CPU_CLOCK_RATE	(PLL_CLK / ((PLL_DIV & DIV_CPU) >> DIV_CPU_SHIFT))	/* MHz clock for the MIPS core */
#define CONFIG_SYS_MIPS_TIMER_FREQ	(LS1X_CPU_CLOCK_RATE / 2)

/* memory */
#define CONFIG_SYS_SDRAM_BASE		0x80000000	/* Cached addr */
#define CONFIG_SYS_SDRAM_SIZE		SZ_256M
#define CONFIG_SYS_INIT_SP_OFFSET	0x00400000
#define CONFIG_SYS_LOAD_ADDR		0x81000000

//#define LS1X_DDR2_USE_16BIT
#define LS1X_DDR2_EIGHT_BANK_MODE

/* Miscellaneous configurable options */
#define CONFIG_SYS_MAXARGS 64	/* max number of command args */
#define CONFIG_SYS_CBSIZE 512 /* Console I/O Buffer Size */

#define CONFIG_SYS_MONITOR_BASE	CONFIG_SYS_TEXT_BASE
//#define CONFIG_SYS_MONITOR_LEN	(256 * 1024)
#define CONFIG_SYS_MALLOC_LEN	(8 * 1024 * 1024)

/* LS1X SPI Settings */
#ifdef CONFIG_LS1X_SPI
#define CONFIG_LS1X_SPI1_ENABLE	/* 使用spi1控制器(复用设置), spi1控制器复用can，如果不使用spi1，最好把该选项关闭 */
#define CONFIG_SPI_CS
//#define CONFIG_SPI_CS_USED_GPIO
#endif

/* Environment settings */
#define CONFIG_ENV_SIZE			0x4000	/* 16KB */
#define CONFIG_ENV_SPI_CS		0
#define CONFIG_ENV_SPI_MAX_HZ	30000000
#define CONFIG_ENV_OFFSET		0xd0000	/* 根据分区大小修改，这里是SPI Flash env的偏移地址 */
#define CONFIG_ENV_SECT_SIZE	(4 << 10)
/*
 * Environment is right behind U-Boot in flash. Make sure U-Boot
 * doesn't grow into the environment area.
 */
#define CONFIG_BOARD_SIZE_LIMIT		CONFIG_ENV_OFFSET

/* NAND settings */
#ifdef CONFIG_NAND
#define CONFIG_SYS_NAND_SELF_INIT
#define CONFIG_SYS_MAX_NAND_DEVICE	1
#define CONFIG_SYS_NAND_BASE	LS1X_NAND_BASE
#define NAND_LS1X_MAX_CHIPS 1
#endif

/* Framebuffer and LCD */
#if defined(CONFIG_VIDEO_LS1X)
#define LS1X_DC0
//#define LS1X_DC0_USE_DEMODE
//#define LS1X_DC1
//#define LS1X_DC1_USE_DEMODE
#define LS1X_DC_MAX 1
#endif
#if defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
#define VIDEO_FB_16BPP_WORD_SWAP
#define CONFIG_SPLASH_SCREEN
#define CONFIG_SPLASH_SCREEN_ALIGN
/* logo 设置 */
#define CONFIG_VIDEO_LOGO
#define CONFIG_VIDEO_BMP_RLE8
#define CONFIG_VIDEO_BMP_LOGO
#define CONFIG_BMP_16BPP
#define CONFIG_BMP_24BPP
#define CONFIG_BMP_32BPP
#endif

#ifdef CONFIG_VIDEO
#define CONSOLE_STDOUT_SETTINGS \
	"stdin=serial\0" \
	"stdout=serial\0" \
	"stderr=serial,vga\0"
#elif CONFIG_DM_VIDEO
#define CONSOLE_STDOUT_SETTINGS \
	"splashimage=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
	"stdin=serial\0" \
	"stdout=serial\0" \
	"stderr=serial,vidconsole\0"
#else
#define CONSOLE_STDOUT_SETTINGS \
	"stdin=serial\0" \
	"stdout=serial\0" \
	"stderr=serial\0"
#endif

/* USB */
#ifdef CONFIG_USB_OHCI_HCD
#define CONFIG_USB_OHCI_NEW
#define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS	8
#endif

#define CONFIG_NET_MULTI
#define CONFIG_NET_RETRY_COUNT          5

#define CONFIG_SYS_BOOTM_LEN		SZ_32M


#endif	/* __LS1B_CORE_CONFIG_H */
